#######################################################
#######################################################
#######################################################
### CREATED BY JONATHAN KING AND JESSICA SCHOENHERR ###
##### REPLICATION DATA FOR "A MATTER OF OPINION?" #####
#######################################################
#######################################################
#######################################################


library(ggplot2)

########################
### PREDICTED VALUES ###
########################

dpDataInd <- read.csv("DeathPenaltyIndependents20221123.csv")

dpDataInd <- as.data.frame(dpDataInd)

dpDataInd$treatmentGroup <- as.factor(dpDataInd$treatmentGroup)

deathPenaltyPredProbInd <- ggplot(dpDataInd, aes(y = predValue, x = treatmentGroup, ymin = lowerValue, ymax = upperValue, color = female, fill = female)) +
	geom_bar(position = position_dodge(), stat = "identity") +
	#facet_wrap(~partisanship) + 
	geom_errorbar(position = position_dodge(0.9), width=0.2, color = "grey25") + 
	theme_bw() +
	xlab("\nOpinion Writer Treatment Groups") +
	ylab("Predicted Value - Decision Thermometer\n") +
	ggtitle("Approval for Pro-Death Penalty Decision\nIndependent Participants\n") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) + 
	scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, 10)) +
	theme(legend.position = "bottom", legend.title = element_blank()) +
	scale_color_manual(values = c("grey75", "grey50"), labels = c("Women", "Men")) +
	scale_fill_manual(values = c("grey75", "grey50"), labels = c("Women", "Men")) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyPredProbInd

#################
### BY GENDER ###
#################

dpDyDxInd <- read.csv("~/Dropbox/JAS-JMK/Opinion\ Writer\ Paper/Data/DeathPenaltyIndependentsDyDxGender20221123.csv")

dpDyDxInd <- as.data.frame(dpDyDxInd)

dpDyDxInd$treatmentGroup <- as.factor(dpDyDxInd$treatmentGroup)

deathPenaltyChangeInd <- ggplot(dpDyDxInd, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	#facet_wrap(~partisanship) +
	theme_bw() +
	ggtitle("Differences Between Female and Male Participants, Approval for Pro-Death Penalty Decision\nIndependent Participants\n") +
	ylab("Difference in Feeling Thermometer (Female - Male)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyChangeInd

#######################
### BY PARTISANSHIP ###
#######################

dpDyDx2Dem <- read.csv("~/Dropbox/JAS-JMK/Opinion\ Writer\ Paper/Data/DeathPenaltyIndependentsDyDxDemocrats20221123.csv")

dpDyDx2Dem <- as.data.frame(dpDyDx2Dem)

dpDyDx2Dem$treatmentGroup <- as.factor(dpDyDx2Dem$treatmentGroup)

deathPenaltyChange2Dem <- ggplot(dpDyDx2Dem, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	facet_wrap(~gender) +
	theme_bw() +
	ggtitle("Differences Between Democrat and Independent Participants, Approval for Pro-Death Penalty Decision") +
	ylab("Difference in Feeling Thermometer (Democrat - Independent)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyChange2Dem

#######################
### BY PARTISANSHIP ###
#######################

dpDyDx2Rep <- read.csv("~/Dropbox/JAS-JMK/Opinion\ Writer\ Paper/Data/DeathPenaltyIndependentsDyDxRepublicans20221123.csv")

dpDyDx2Rep <- as.data.frame(dpDyDx2Rep)

dpDyDx2Rep$treatmentGroup <- as.factor(dpDyDx2Rep$treatmentGroup)

deathPenaltyChange2Rep <- ggplot(dpDyDx2Rep, aes(y = change, x = treatmentGroup, ymin = lowerCI, ymax = upperCI)) +
	geom_hline(aes(yintercept = 0), color = "grey75", size = 1.5) +
	geom_pointrange(fatten = 1, size = 1) +
	facet_wrap(~gender) +
	theme_bw() +
	ggtitle("Differences Between Republican and Independent Participants, Approval for Pro-Death Penalty Decision") +
	ylab("Difference in Feeling Thermometer (Republican - Independent)\n") +
	xlab("\nOpinion Writer Treatment Groups") +
	theme(plot.title = element_text(hjust = 0.5)) +
	scale_x_discrete(labels = c("Liberal\nMale\nJustice", "Conservative\nMale\nJustice", "Liberal\nFemale\nJustice", "Conservative\nFemale\nJustice", "Control")) +
	scale_y_continuous(limits = c(-45, 45), breaks = seq(-45, 45, 10)) +
	theme(strip.text.x = element_text(size = 12))
deathPenaltyChange2Rep

